<template>
  <div>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="3">
          <el-input
            placeholder="请输入姓名"
            v-model="queryInfo.query.name"
            clearable
            @clear="getStudents"
          ></el-input
        ></el-col>
        <!-- <el-col :span="3">
          <el-input
            placeholder="请输入市场部"
            v-model="queryInfo.query.market"
            clearable
            @clear="getStudents"
          ></el-input
        ></el-col> -->
        <el-col :span="3" v-permission="['admin']">
          <el-select
            v-model="queryInfo.query.depar_id"
            placeholder="请选择学院"
            clearable
          >
            <el-option
              v-for="item in deparoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option> </el-select
        ></el-col>
        <el-col :span="3" v-permission="['admin']">
          <el-select
            v-model="queryInfo.query.cls_id"
            placeholder="班级:请先选择学院"
            clearable
            :disabled="fdyjs"
          >
            <el-option
              v-for="item in sclsoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option> </el-select
        ></el-col>
        <!-- <el-col :span="3" v-permission="['admin']">
          <el-select
            v-model="queryInfo.query.fdy_id"
            clearable
            :disabled="fdyjs"
            placeholder="导员:请先选择学院"
          >
            <el-option
              v-for="item in sfdyoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="3" v-permission="['admin']">
          <el-select
            v-model="queryInfo.query.js_id"
            clearable
            :disabled="fdyjs"
            placeholder="讲师:请先选择学院"
          >
            <el-option
              v-for="item in sjsoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col> -->
        <!-- <el-col :span="3" v-permission="['fdy']">
          <el-select
            v-model="queryInfo.query.cls_id"
            placeholder="请先选择班级"
            clearable
            :disabled="fdyjs"
          >
            <el-option
              v-for="item in sclsoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option> </el-select
        ></el-col>
        <el-col :span="3" v-permission="['fdy']">
          <el-select
            v-model="queryInfo.query.js_id"
            clearable
            :disabled="fdyjs"
            placeholder="请先选择讲师"
          >
            <el-option
              v-for="item in sjsoptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col> -->
        <!-- <el-col :span="3">
            <el-select
              v-model="queryInfo.query.sex"
              placeholder="选择性别"
              clearable
            >
              <el-option
                v-for="item in sexoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option> </el-select
          ></el-col> -->
        <el-col :span="3">
          <el-input
            placeholder="请输入宿舍号"
            v-model="queryInfo.query.dormnumber"
            clearable
            @clear="getStudents"
          ></el-input
        ></el-col>
        <el-col :span="1">
          <el-button
            type="primary"
            icon="el-icon-search"
            circle
            @click="getStudents"
          ></el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="danger" @click="clearsearch">重置</el-button>
        </el-col>

        <el-col :span="2">
          <el-button type="success" @click="scoreDialogVisibletype = true">
            批量导入违纪</el-button
          >
        </el-col>
      </el-row>
      <!-- 用户列表区域 -->
      <span v-if="studentlist.length != 0">
        <el-table
          ref="multipleTable"
          style="margin-top: 40px"
          :data="studentlist"
          border
          stripe
        >
          <el-table-column type="index" label="#"></el-table-column>
          <el-table-column label="姓名" prop="name"></el-table-column>
          <el-table-column label="积分" prop="score"></el-table-column>
          <el-table-column label="性别" prop="sex">
            <template slot-scope="scope">
              <span v-if="scope.row.sex == 0">男</span>
              <span v-if="scope.row.sex == 1">女</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="重修次" prop="anewconunt"></el-table-column> -->
          <el-table-column label="手机号" prop="phone"></el-table-column>
          <!-- <el-table-column
          label="家长手机号"
          prop="family_phone"
        ></el-table-column> -->
          <!-- <el-table-column label="关系" prop="relations"></el-table-column> -->
          <!-- <el-table-column label="学生地址" prop="address"></el-table-column> -->
          <el-table-column label="宿舍号-床位">
            <template slot-scope="scope">
              {{ scope.row.dormnumber }}-{{ scope.row.bednumber }}
            </template>
          </el-table-column>
          <el-table-column label="市场部" prop="market"></el-table-column>
          <!-- <el-table-column label="身份证" prop="idcardnumber"></el-table-column> -->
          <el-table-column label="部门" prop="department">
            <template slot-scope="scope">
              <span v-if="scope.row.department">
                {{ scope.row.department }}
              </span>
              <span v-else>暂无部门</span>
            </template>
          </el-table-column>
          <el-table-column label="班级" prop="clsname">
            <template slot-scope="scope">
              <span v-if="scope.row.clsname">
                {{ scope.row.clsname }}
              </span>
              <span v-else>暂无分配班级</span>
            </template>
          </el-table-column>

          <el-table-column label="讲师" prop="js_id">
            <template slot-scope="scope">
              <span v-if="scope.row.clsname">
                <span v-if="scope.row.lecturer">{{ scope.row.lecturer }}</span>
                <span v-else>班级暂无讲师</span>
              </span>
              <span v-else>暂无班级</span>
            </template>
          </el-table-column>
          <el-table-column label="导员" prop="fdy_id">
            <template slot-scope="scope">
              <span v-if="scope.row.clsname">
                <span v-if="scope.row.counsellor">{{
                  scope.row.counsellor
                }}</span>
                <span v-else>班级暂无导员</span>
              </span>
              <span v-else>暂无班级</span>
            </template>
          </el-table-column>

          <el-table-column label="操作" width="280px">
            <template slot-scope="scope">
              <!-- 加分按钮 -->
              <el-button
                type="primary"
                size="mini"
                @click="awaDialoghand(scope.row)"
                v-permission="['admin', 'fdy']"
                >加分</el-button
              >
              <!-- 扣分按扭 -->
              <el-button
                type="success"
                size="mini"
                @click="subDialoghand(scope.row)"
                v-permission="['admin', 'dc']"
                >减分</el-button
              >
              <!-- 过往违纪 -->
              <el-button
                type="warning"
                size="mini"
                @click="hisDialoghand(scope.row)"
                v-permission="['admin', 'fdy', 'js']"
                >记录</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </span>
      <span v-else class="imag"> 请搜索 </span>
      <!-- 分页区域 -->
      <el-pagination
        style="margin-top: 20px"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.page"
        :page-sizes="[5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>



    <!-- 批量导入违纪类型选择 -->
    <el-dialog
      title="批量导入学生信息"
      :visible.sync="scoreDialogVisibletype"
      width="50%"
    >
      <!-- action="http://192.168.3.3:8000/api/StudentScores/uploadexcel"-->
      <el-switch
        v-model="disciplinetype_switch"
        active-text="学院违纪"
        inactive-text="宿舍违纪"
      >
      </el-switch>
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="scoreDialogVisibletype = false">取 消</el-button>
        <el-button type="primary" @click="addstudentscoretype">确 定</el-button>
      </span>
    </el-dialog>


    <!-- 批量导入学院违纪对话框 -->
    <el-dialog
      title="导入宿舍违纪"
      :visible.sync="scoreDialogVisible"
      width="50%"
    >
      {{ piliang_sub_error }}
      <el-upload
        class="upload-demo"
        name="scorefile"
        drag
        :data="dis_id"
        :headers="header"
        action="http://192.168.3.3:8000/api/StudentScores/uploadexcel_xue"
        :auto-upload="false"
        ref="scoreFile"
        :on-success="uploadSuccess"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      </el-upload>
      <el-link
        href="http://101.34.188.212:8001/api/download_excel_sub_xue"
        target="_blank"
        type="primary"
        icon="el-icon-download"
        >下载学院减分模板</el-link
      >
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="scoreDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addstudentscore">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 批量导入宿舍违纪对话框 -->
    <el-dialog
      title="导入宿舍违纪"
      :visible.sync="scoreDialogVisiblesu"
      width="50%"
    >
      {{ piliang_sub_error }}
      <el-upload
        class="upload-demo"
        name="scorefile"
        drag
        :headers="header"
        :data="dis_id"
        action="http://192.168.3.3:8000/api/StudentScores/uploadexcel_su"
        :auto-upload="false"
        ref="scoreFile"
        :on-success="uploadSuccess"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      </el-upload>
      <el-link
        href="http://101.34.188.212:8001/api/download_excel_sub_su"
        target="_blank"
        type="primary"
        icon="el-icon-download"
        >下载宿舍减分模板</el-link
      >
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="scoreDialogVisiblesu = false">取 消</el-button>
        <el-button type="primary" @click="addstudentscore">确 定</el-button>
      </span>
    </el-dialog>



    <!--综合积分加分-->
    <el-dialog
      title="学生综合积分加分"
      :visible.sync="awaDialogVisible"
      width="60%"
      @close="awaDialogClosed"
    >
      <el-descriptions class="margin-top" title="学生信息" :column="3" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            姓名
          </template>
          {{ this.awaForm.name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            身份证
          </template>
          {{ this.awaForm.idcardnumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            学院
          </template>
          {{ this.awaForm.depar }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            班级
          </template>
          {{ this.awaForm.cls }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            讲师
          </template>
          {{ this.awaForm.lecturer }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            导员
          </template>
          {{ this.awaForm.counsellor }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            宿舍号
          </template>
          {{ this.awaForm.dormnumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            家庭住址
          </template>
          {{ this.awaForm.address }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            市场部
          </template>
          {{ this.awaForm.market }}
        </el-descriptions-item>
      </el-descriptions>
      <div style="display: inline-block; width: 500px; margin-top: 60px">
        <el-form
          :model="awaForm"
          :rules="awaFormRules"
          ref="awaFormRef"
          label-width="140px"
          class="awa-form"
        >
          <el-form-item label="加分项" prop="content">
            <el-autocomplete
              v-model="state"
              :fetch-suggestions="awaquerySearchAsync"
              placeholder="请输入加分项"
              @select="awahandleSelect"
              clearable
            ></el-autocomplete>
          </el-form-item>
          <el-form-item label="分数" prop="Marks">
            <el-tag type="success" effect="dark" style="width: 150px">
              <span v-if="awaForm.Marks"> {{ awaForm.Marks }}</span>
              <span v-else>请先选加分项</span>
            </el-tag>
          </el-form-item>
          <el-form-item label="日期" prop="data">
            <el-date-picker
              v-model="awaForm.data"
              align="right"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </el-form-item>
        </el-form>
      </div>
      <div :class="{ awaupload: awauploadbool, awaupload2: awauploadbool2 }">
        <el-upload
          class="upload-demo"
          :headers="header"
          ref="awaupload"
          action="http://101.34.188.212:8001/api/StudentScores"
          :limit="1"
          :on-preview="awahandlePreview"
          :on-remove="awahandleRemove"
          :on-success="awahandsuccess"
          :on-exceed="awahandexceed"
          :on-change="awahandchange"
          accept="jpg"
          :auto-upload="false"
          :data="awaForm"
          list-type="picture-card"
          style="margin-bottom: 20px"
          name="awafile"
        >
          <i slot="default" class="el-icon-plus"></i>
        </el-upload>
      </div>
      <span slot="footer" class="dialog-footer" style="padding-left: 150px">
        <el-button @click="awaDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="awascore">确 定</el-button>
      </span>
    </el-dialog>
    <!--综合积分扣分-->
    <el-dialog
      title="扣分"
      :visible.sync="subDialogVisibles"
      width="50%"
      @close="subDialogClosed"
      ><el-descriptions class="margin-top" title="学生信息" :column="3" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            姓名
          </template>
          {{ this.subForm.name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            身份证
          </template>
          {{ this.subForm.idcardnumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            学院
          </template>
          {{ this.subForm.depar }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            班级
          </template>
          {{ this.subForm.cls }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            讲师
          </template>
          {{ this.subForm.lecturer }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            导员
          </template>
          {{ this.subForm.counsellor }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            宿舍号
          </template>
          {{ this.subForm.dormnumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            家庭住址
          </template>
          {{ this.subForm.address }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            市场部
          </template>
          {{ this.subForm.market }}
        </el-descriptions-item>
      </el-descriptions>
      <div style="display: inline-block; width: 500px; margin-top: 60px">
        <el-form
          :model="subForm"
          :rules="subFormRules"
          ref="subFormRef"
          label-width="140px"
          class="sub-form"
        >
          <el-form-item label="违纪类型" prop="disciplinetype">
            <el-select
              v-model="subForm.disciplinetype"
              placeholder="请选择违纪类型"
            >
              <el-option
                v-for="item in Disciplinetypeselect"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="扣分项" prop="content">
            <el-autocomplete
              v-model="state"
              :fetch-suggestions="subquerySearchAsync"
              placeholder="请输入内容"
              @select="subhandleSelect"
              clearable
            ></el-autocomplete>
          </el-form-item>
          <el-form-item label="分数" prop="Marks">
            <!-- <el-tag type="success" effect="dark" style="width: 150px"> -->
            <span v-if="subForm.Marks"> {{ subForm.Marks }}</span>
            <span v-else>请先选扣分项</span>
            <!-- </el-tag> -->
          </el-form-item>
          <el-form-item label="日期" prop="data">
            <el-date-picker
              v-model="subForm.data"
              align="right"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </el-form-item>
          <span v-if="subForm.disciplinetype == 1">
            <el-form-item label="课节" prop="course">
              <el-radio-group v-model="subForm.anp">
                <el-radio-button label="上午"></el-radio-button>
                <el-radio-button label="下午"></el-radio-button>
                <el-radio-button label="晚上"></el-radio-button>
              </el-radio-group>
              <el-select v-model="subForm.kejie" placeholder="请选择课节">
                <el-option
                  v-for="item in courseoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select> </el-form-item
          ></span>
        </el-form>
      </div>
      <div :class="{ subupload: subuploadbool, subupload2: subuploadbool2 }">
        <el-upload
          class="upload-demo"
          :headers="header"
          ref="subupload"
          action="http://101.34.188.212:8001/api/StudentScores"
          :limit="1"
          :on-preview="subhandlePreview"
          :on-remove="subhandleRemove"
          :on-success="subhandsuccess"
          :on-exceed="subhandexceed"
          :on-change="subhandchange"
          accept="jpg"
          :file-list="subForm.avatar"
          :auto-upload="false"
          :data="subForm"
          list-type="picture-card"
          style="margin-bottom: 20px"
          name="subfile"
        >
          <i slot="default" class="el-icon-plus"></i>
        </el-upload>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="subDialogVisibles = false">取 消</el-button>
        <el-button type="primary" @click="subscore">确 定</el-button>
      </span>
    </el-dialog>

    <!--综合积分记录-->
    <el-dialog
      title="记录"
      :visible.sync="hisDialogVisible"
      width="50%"
      height="10%"
      @close="hisDialogClosed"
    >
      <el-tabs v-model="activeName">
        <!-- <el-tab-pane label="减分记录" name="subscore"> -->
        <div style="height: 300px; width: 100%; background-color: #ccc">
          <!-- 这里的标签名称要和main.js文件中定义的组件名称保持一致 -->
          <happy-scroll color="rgba(0,0,0,0.5)" size="5">
            <!-- 内层盒子——内容区 -->
            <div class="con1">
              <el-timeline style="margin-top: 15px">
                <el-timeline-item
                  v-for="(activity, index) in subactivities"
                  :key="index"
                  :icon="activity.icon"
                  :type="activity.type"
                  :color="activity.color"
                  :size="activity.size"
                  :timestamp="activity.timestamp"
                >
                  {{ activity.content }}
                </el-timeline-item>
              </el-timeline>
            </div>
          </happy-scroll>
        </div>
        <!-- </el-tab-pane> -->
        <!-- <el-tab-pane label="加分记录" name="awascore"> -->
        <div
          style="
            height: 300px;
            width: 100%;
            background-color: #ccc;
            margin-top: 40px;
          "
        >
          <!-- 这里的标签名称要和main.js文件中定义的组件名称保持一致 -->
          <happy-scroll color="rgba(0,0,0,0.5)" size="5">
            <!-- 内层盒子——内容区 -->
            <div class="con2">
              <el-timeline style="margin-top: 15px">
                <el-timeline-item
                  v-for="(activity, index) in awaactivities"
                  :key="index"
                  :icon="activity.icon"
                  :type="activity.type"
                  :color="activity.color"
                  :size="activity.size"
                  :timestamp="activity.timestamp"
                >
                  {{ activity.content }}
                </el-timeline-item>
              </el-timeline>
            </div>
          </happy-scroll>
        </div>
        <!-- </el-tab-pane> -->
      </el-tabs>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisibleImg">
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
  </div>
</template>

<script>
import { getHeader } from "utils/login";
import { getStudents } from "network/api/students";
import {
  getallDepartment,
  // getdyalljs,
  // getdyallbj,
} from "network/api/department";
import { getcollcls } from "network/api/classes";
import {
  noGetAwardedMarkss,
  noGetSubtractMarks,
  CreateMarksLists,
  GetScorelistOne,
  GetDisciplinetypes,
} from "network/api/studentscore";
import permission from "@/directive/permission/index.js"; // 权限判断指令

export default {
  data() {
    return {
      piliang_sub_error: "",
      activeName: "subscore",
      fdyjs: true,
      zxc: false,
      awauploadbool: true,
      awauploadbool2: true,
      subuploadbool: true,
      subuploadbool2: true,
      //学生综合积分管理
      awaDialogVisible: false,
      subDialogVisibles: false,
      hisDialogVisible: false,
      allhisscorelist: [],
      awaactivities: [],
      subactivities: [],
      awaForm: {
        student: "",
        name: "",
        sex: null,
        idcardnumber: "",
        depar: "",
        cls: "",
        lecturer: "",
        counsellor: "",
        dormnumber: "",
        address: "",
        market: "",
        state: null,
        content: "",
        Marks: null,
        js_id: null,
        fdy_id: null,
        depar_id: null,
        cls_id: null,
        bednumber: null,
        // avatar: [],
        // data: null,
        // create_data:'',
        // update_data:'',
      },
      subForm: {
        student: "",
        name: "",
        sex: null,
        classid: null,
        idcardnumber: "",
        depar: "",
        cls: "",
        lecturer: "",
        counsellor: "",
        dormnumber: null,
        bednumber: null,
        address: "",
        market: "",
        state: null,
        disciplinetype: "",
        content: "",
        Marks: null,
        js_id: null,
        fdy_id: null,
        depar_id: null,
        cls_id: null,
        // avatar: [],
        // data: null,
        anp: "",
        kejie: "",
        course: "",
        // create_data:'',
        // update_data:'',
      },
      awaFormRules: {},
      subFormRules: {},

      header: {},
      disciplinetype_switch: true,
      dis_id: {
        disciplinetype_id: null,
      },
      scoreDialogVisibletype: false,
      scoreDialogVisible: false,
      scoreDialogVisiblesu: false,
      AwardedMarkslist: [],
      SubtractMarkslistall: [],
      SubtractMarkslist: [{ value: "" }],
      state: "",
      timeout: null,
      Disciplinetypeselect: [],
      courseoptions: [
        {
          value: "第一节课",
          label: "第一节课",
        },
        {
          value: "第二节课",
          label: "第二节课",
        },
        {
          value: "第三节课",
          label: "第三节课",
        },
        {
          value: "第四节课",
          label: "第四节课",
        },
      ],

      dialogVisibleImg: false,
      dialogImageUrl: "",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "前天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 2);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      //
      clsoptionsall: [],
      deparoptions: [],
      sclsoptions: [],
      sjsoptions: [{ value: "", label: "请选择讲师" }],
      sfdyoptions: [{ value: "", label: "请选择导员" }],
      sexoptions: [
        {
          value: 0,
          label: "男",
        },
        {
          value: 1,
          label: "女",
        },
      ],
      queryInfo: {
        query: {
          js_id: null,
          fdy_id: null,
          name: "",
          market: "",
          depar_id: null,
          cls_id: null,
          sex: "",
          dormnumber: "",
        },
        // 当前的页数
        page: 1,
        // 当前每页显示多少条数据
        pagesize: 5,
      },
      total: 0,
      studentlist: [],
    };
  },
  async created() {
    const roles = this.$store.state.user.roles;
    const id = window.sessionStorage.getItem("userid");
    console.log(roles, 123456, roles.indexOf("fdy"));
    if (roles.indexOf("fdy") != -1) {
      this.queryInfo.query.fdy_id = id;
      // this.fdyjs = false;
      // this.getdyalljs(id);
      // this.getdyallbj(id);
    } else if (roles.indexOf("js") != -1) {
      console.log(7777777);
      this.queryInfo.query.js_id = id;
    }
    this.header = getHeader();
    this.getallDepartment();
    this.noGetAwardedMarkss();
    this.noGetSubtractMarks();
    this.GetDisciplinetypes();
  },
  watch: {
    "subForm.disciplinetype": function (val) {
      let flag = false;
      this.SubtractMarkslist = [];
      this.SubtractMarkslistall.forEach((item) => {
        console.log(item, 123456);
        if (item.Disciplinetype_id == val) {
          flag = true;
          const obj = {};
          if (item.expel) {
            item.Marks = "开除";
          }
          obj.value = item.content;
          obj.Marks = item.Marks;
          obj.id = item.id;
          this.SubtractMarkslist.push(obj);
        }
      });
      if (!flag) {
        this.SubtractMarkslist = [{ value: "该违纪类型暂无" }];
      }
    },
    awaDialogVisible: function (val) {
      if (val == false) {
        this.$refs.awaupload.clearFiles();
        this.awauploadbool = true;
        this.state = "";
      }
    },
    // subDialogVisibles: function (val) {
    //   console.log(12,val)
    //   if (!val) {
    //     this.$refs.subupload.clearFiles();
    //     this.subuploadbool = false;
    //     this.state = "";
    //   }
    //   this.subuploadbool = true;
    // },
    "queryInfo.query.depar_id": function (val) {
      console.log("id", val);
      if (val) {
        this.sjsoptions = [];
        this.sfdyoptions = [];
        // this.sgetDepartmentjs(val);
        // this.sgetDepartmentfdy(val);
        this.sgetclassname(val);
        this.fdyjs = false;
      } else {
        this.queryInfo.query.cls_id = "";
        this.queryInfo.query.js_id = "";
        this.queryInfo.query.fdy_id = "";
        this.fdyjs = true;
        this.jsoptions = [];
        this.fdyoptions = [];
      }
    },
    state: function (val) {
      if (!val) {
        this.awaForm.content = "";
        this.subForm.content = "";
      }
    },
  },
  directives: { permission },
  methods: {
    uploadSuccess(response, file, fileList) {
      console.log(response, file, fileList);
      if (response.state == "OK") {
        this.acoreDialogVisible = false;
        this.acoreDialogVisiblesu=false
        this.piliang_sub_error = "";
        this.$message.success("批量导入成功");
      } else if (response.state == "NO") {
        this.$message.error(response.error);
        this.piliang_sub_error = response.erroro;
      }
      // this.GettratMarksLists();
    },
    addstudentscoretype() {
      if (this.disciplinetype_switch) {
        this.dis_id.disciplinetype_id = 1;
        this.scoreDialogVisible = true;
      } else {
        this.dis_id.disciplinetype_id = 2;
        scoreDialogVisiblesu = true;
      }
    },
    addstudentscore() {
      // this.$refs.addFormRef1.validate(async (valid) => {
      // if (!valid) return;

      this.$refs.scoreFile.submit();

      //隐藏批量添加用户的对话框
      // });
    },
    async GetSubtractMarks() {
      const res = await GetSubtractMarks(this.subForm);
      console.log(res);
    },
    async GetDisciplinetypes() {
      const res = await GetDisciplinetypes();
      res.forEach((item) => {
        const obj = {};
        obj.value = item.id;
        obj.label = item.content;
        this.Disciplinetypeselect.push(obj);
      });
    },
    awahandleRemove(file) {
      console.log("删除文件回调");
      if (this.$refs.awaupload.uploadFiles.length == 0) {
        this.awauploadbool = true;
      } else {
        this.awauploadbool = false;
      }
      this.$refs.awaupload.clearFiles();
    },
    awahandlePreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisibleImg = true;
    },
    awahandsuccess(result) {
      if (result) {
        this.awaDialogVisible = false;
        this.$message.success("添加成功");
      } else {
        this.$message.error("添加失败");
      }
    },
    awahandchange() {
      if (this.$refs.awaupload.uploadFiles.length == 0) {
        this.awauploadbool = true;
      } else {
        this.awauploadbool = false;
      }
    },
    awahandexceed() {
      this.$message.error("上传文件超出限制(1个)");
    },
    subhandleRemove(file) {
      console.log("删除文件回调");
      if (this.$refs.subupload.uploadFiles.length == 0) {
        this.subuploadbool = true;
      } else {
        this.subuploadbool = false;
      }
      this.$refs.subupload.clearFiles();
    },
    subhandlePreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisibleImg = true;
    },
    subhandsuccess(result) {
      if (result) {
        this.subDialogVisibles = false;
        this.$message.success("添加成功");
      } else {
        this.$message.error("添加失败");
      }
    },
    subhandchange() {
      if (this.$refs.subupload.uploadFiles.length == 0) {
        this.subuploadbool = true;
      } else {
        this.subuploadbool = false;
      }
    },
    subhandexceed() {
      this.$message.error("上传文件超出限制(1个)");
    },
    //获取部门下的班级名称列表

    async sgetclassname(id) {
      console.log("asfs");
      const res = await getcollcls(id);
      console.log("sad", res);
      this.sclsoptions = [];
      res.forEach((item) => {
        const obj = {};
        obj.value = item.id;
        obj.label = item.name;
        this.sclsoptions.push(obj);
      });
    },
    async sgetDepartmentjs(id) {
      const res = await getallDepartment({ depar_id: id, role: "讲师" });
      console.log(res, 78978979, "讲师");
      if (res.code == 200) {
        res.data.forEach((item) => {
          const obj = {};
          obj.value = item.id;
          obj.label = item.name;
          this.sjsoptions.push(obj);
        });
      }
    },
    async sgetDepartmentfdy(id) {
      const res = await getallDepartment({ depar_id: id, role: "导员" });
      console.log(res, 78978979, "导员");
      if (res.code == 200) {
        res.data.forEach((item) => {
          const obj = {};
          obj.value = item.id;
          obj.label = item.name;
          this.sfdyoptions.push(obj);
        });
      }
    },
    //获取导员所带的班级  与   讲师
    //获取导员带的班级的所有讲师
    async getdyalljs(id) {
      const res = await getdyalljs(id);
      this.sjsoptions = [];
      console.log(res, 1111);
      res.data.forEach((item) => {
        const obj = {};
        obj.value = item.id;
        obj.label = item.name;
        this.sjsoptions.push(obj);
      });
    },
    //获取导员带的所有班级
    async getdyallbj(id) {
      this.sclsoptions = [];
      const res = await getdyallbj(id);
      console.log(res, 1111);
      res.data.forEach((item) => {
        const obj = {};
        obj.value = item.id;
        obj.label = item.name;
        this.sclsoptions.push(obj);
      });
    },
    // 加分
    async awaDialoghand(row) {
      console.log(row, 1111111111111);
      const {
        id,
        name,
        sex,
        idcardnumber,
        department,
        clsname,
        lecturer,
        counsellor,
        dormnumber,
        bednumber,
        address,
        market,
      } = row;
      this.awaForm.name = name;
      this.awaForm.student = id;
      this.awaForm.bednumber = bednumber;
      this.awaForm.sex = sex;
      this.awaForm.idcardnumber = idcardnumber;
      this.awaForm.depar = department;
      this.awaForm.cls = clsname;
      this.awaForm.lecturer = lecturer;
      this.awaForm.counsellor = counsellor;
      this.awaForm.address = address;
      this.awaForm.market = market;
      this.awaForm.dormnumber = dormnumber;
      this.awaForm.state = true;
      this.awaDialogVisible = true;
    },
    awascore() {
      this.$refs.awaFormRef.validate(async (valid) => {
        if (!valid) return;

        this.awaForm.status = 0;
        if (this.$refs.awaupload.uploadFiles.length != 0) {
          console.log("有图片");
          this.$refs.awaupload.submit();
        } else {
          const res = await CreateMarksLists(this.awaForm);
          if (res.code == 200) {
            console.log("无图片添加成功");
          }
        }
      });
    },
    awaDialogClosed() {
      this.awaForm = {
        name: "",
        idcardnumber: "",
        depar: "",
        cls: "",
        lecturer: "",
        counsellor: "",
        dormnumber: "",
        address: "",
        market: "",
        state: null,
        content: "",
        Marks: null,
        depar_id: null,
        cls_id: null,
        js_id: null,
        fdy_id: null,
        // avatar: [],
        // data: null,
        // create_data:'',
        // update_data:'',
      };
      this.state = "";
      this.$refs.awaFormRef.resetFields();
    },
    // 扣分
    async subDialoghand(row) {
      console.log(456, row);
      const {
        id,
        name,
        sex,
        idcardnumber,
        department,
        clsname,
        lecturer,
        counsellor,
        dormnumber,
        bednumber,
        address,
        market,
        cls_id,
      } = row;
      this.subForm.student = id;

      this.subForm.classid = cls_id;
      this.subForm.name = name;
      this.subForm.bednumber = bednumber;
      this.subForm.sex = sex;
      this.subForm.idcardnumber = idcardnumber;
      this.subForm.depar = department;
      this.subForm.cls = clsname;
      this.subForm.lecturer = lecturer;
      this.subForm.counsellor = counsellor;

      this.subForm.address = address;
      this.subForm.market = market;
      this.subForm.dormnumber = dormnumber;
      this.subForm.state = false;
      this.subDialogVisibles = true;
    },
    subscore() {
      this.$refs.subFormRef.validate(async (valid) => {
        if (!valid) return;
        this.subForm.course = this.subForm.anp + this.subForm.kejie;
        this.subForm.status = 0;
        if (this.$refs.subupload.uploadFiles.length != 0) {
          console.log("有图片");
          this.$refs.subupload.submit();
        } else {
          const res = await CreateMarksLists(this.subForm);
          if (res.code == 200) {
            console.log("无图片添加成功");
          }
        }
      });
    },
    subDialogClosed() {
      (this.subForm = {
        name: "",
        idcardnumber: "",
        depar: "",
        cls: "",
        lecturer: "",
        counsellor: "",
        dormnumber: "",
        address: "",
        market: "",
        state: null,
        disciplinetype: "",
        content: "",
        Marks: null,
        // avatar: [],
        // data: null,
        anp: "",
        kejie: "",
        course: "",
        // create_data:'',
        // update_data:'',
      }),
        this.$refs.subFormRef.resetFields();
    },
    // 记录
    async hisDialoghand(row) {
      var moment = require("moment");
      const res = await GetScorelistOne(row.id);
      this.allhisscorelist = [];
      this.awaactivities = [];
      this.subactivities = [];
      if (res.code == 200) {
        this.allhisscorelist = res.data;
        this.$message.success("获取单个学生信息成功");
        this.hisDialogVisible = true;
        res.data.forEach((item) => {
          if (item.state && item.status == 1) {
            let date = moment(item.data);
            const obj = {};
            obj.content = item.content + "加" + item.Marks + "分";
            obj.timestamp = date.format("YYYY-MM-DD");
            obj.size = "large";
            obj.type = "success";
            obj.icon = "el-icon-more";
            this.awaactivities.push(obj);
          } else if (!item.state && item.status == 1) {
            let date = moment(item.data);
            const obj = {};
            obj.content = item.content + "扣" + item.Marks + "分";
            obj.timestamp = date.format("YYYY-MM-DD") + item.course;
            obj.size = "large";
            obj.type = "primary";
            obj.icon = "el-icon-more";
            this.subactivities.push(obj);
          }
        });
      } else {
        this.$message.error("获取单个学生信息失败");
      }
    },
    hisDialogClosed() {
      this.allhisscorelist = [];
      this.awaactivities = [];
      this.subactivities = [];
      // this.$refs.hisFormRef.resetFields();
    },

    awaquerySearchAsync(queryString, cb) {
      let AwardedMarkslist = this.AwardedMarkslist;
      let results = queryString
        ? AwardedMarkslist.filter(this.awacreateStateFilter(queryString))
        : AwardedMarkslist;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 100 * Math.random());
    },
    awacreateStateFilter(queryString) {
      return (state) => {
        return (
          state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    awahandleSelect(item) {
      this.awaForm.content = item.value;
      this.awaForm.Marks = item.Marks;
    },

    subquerySearchAsync(queryString, cb) {
      let SubtractMarkslist = this.SubtractMarkslist;
      let results = queryString
        ? SubtractMarkslist.filter(this.subcreateStateFilter(queryString))
        : SubtractMarkslist;

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 100 * Math.random());
    },
    subcreateStateFilter(queryString) {
      return (state) => {
        return (
          state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    subhandleSelect(item) {
      if (item.value == "请先选择违纪类型" || item.value == "该违纪类型暂无") {
        console.log("1");
      } else {
        this.subForm.content = item.value;
        this.subForm.Marks = item.Marks;
      }
    },

    async getStudents(
      $event,
      page = this.queryInfo.page,
      page_size = this.queryInfo.pagesize
    ) {
      console.log(111, this.queryInfo.query);
      const result = await getStudents({
        search: this.queryInfo.query,
        page,
        page_size,
      });
      if (result.code == 200) {
        console.log(result.data, 1234123);
        this.$message.success("获取学生列表成功！");
        this.studentlist = result.data; //列表中展示的数据内容
        this.total = result.count; //数据总条数
      } else {
        return this.$message.error("获取学生列表失败！");
      }
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getStudents();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage;
      this.getStudents();
    },
    //获取所有学院
    async getallDepartment() {
      const res = await getallDepartment();
      const content = res.data;
      this.deparoptions = [];
      content.forEach((item) => {
        if (item.label == 1) {
          let obj = {};
          obj.value = item.id;
          obj.label = item.name;
          this.deparoptions.push(obj);
        }
      });
    },
    //获取所有加分项
    async noGetAwardedMarkss() {
      const res = await noGetAwardedMarkss();
      if (res) {
        res.forEach((item) => {
          const obj = {};
          obj.value = item.content;
          obj.id = item.id;
          obj.Marks = item.Marks;
          this.AwardedMarkslist.push(obj);
        });
        // this.$message.success("获取加分项数据成功");
      }
    },
    //获取所有扣分项
    async noGetSubtractMarks() {
      const res = await noGetSubtractMarks();
      console.log(res, 12345);
      if (res) {
        this.SubtractMarkslistall = res;
        // this.$message.success("获取扣分项数据成功");
      }
    },
    //清空搜索的内容
    clearsearch() {
      const js_id = this.queryInfo.query.js_id;
      const fdy_id = this.queryInfo.query.fdy_id;
      this.queryInfo.query = {
        name: "",
        market: "",
        depar_id: "",
        cls_id: "",
        sex: "",
        dormnumber: "",
      };
      this.queryInfo.query.js_id = js_id;
      this.queryInfo.query.fdy_id = fdy_id;
    },
  },
};
</script>

<style lang="less" scoped>
.awaupload {
  display: inline-block;
  position: relative;
  bottom: 150px;
}
.awaupload2 {
  display: inline-block;
  position: relative;
  left: 150px;
}
.subupload {
  display: inline-block;
  position: relative;
  bottom: 150px;
}
.subupload2 {
  display: inline-block;
  position: relative;
  left: 80px;
}

.imag {
  width: 100%;
  display: inline-block;
}
.imag img {
  width: 1000px;
  margin: 0 auto;
}
.awa-form,
.aub-form {
  margin-top: 50px;
}
</style>
